package com.cjl.learn.postProcessor;

import com.cjl.learn.bean.Bird;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * Created by Enzo Cotter on 2019-07-21.
 */
@Component
public class MyBeanProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if ("bird".equals(beanName)) {
            System.out.println("postProcessBeforeInitialization..." + beanName + ", name=" + ((Bird) bean).getName());
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if ("bird".equals(beanName)) {
            System.out.println("postProcessAfterInitialization..." + beanName);
        }
        return bean;
    }

}
